#include "serverclient.h"
#include <QHostAddress>
#include "../common/comiocontroller.h"

ServerClient::ServerClient(QTcpSocket *cTcpClient)
{
    this->m_cTcpClient = cTcpClient;
    //disconnect
    connect(m_cTcpClient, SIGNAL(disconnected()), this, SLOT(slot_disconnected()));
    connect(m_cTcpClient, SIGNAL(readyRead()), this, SLOT(slot_readReady()));
    //TODO read write signal

}


void ServerClient::slot_disconnected()
{
    ComIOController::getInstance()->msgOutput(QString("<ServerClient::slot_disconnected>:")+m_cTcpClient->peerAddress().toString()+" has disconnected");
    m_cTcpClient->deleteLater();
    //notify manager to delete this ServerClient
    emit sig_disconnected(this);
}

void ServerClient::slot_readReady()
{
    ComIOController::getInstance()->msgOutput(QString("<ServerClient::slot_disconnected>:New data has arrived."), MSG_DEBUG);

}
